package com.base.controller;

import javax.servlet.http.HttpSession;

import com.beust.jcommander.internal.Maps;
import com.base.po.voip.CallbackRedirectTable;
import com.base.service.CallbackRedirectTableService;
import com.base.service.UsersConfigService;
import com.base.service.UsersRebateConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.base.service.UsersService;

import java.util.Map;

/**
 * 账户配置
 *
 * @author f 优化日期：10-11
 *
 */
@Controller
@RequestMapping("/admin")
public class AllocationsIndexController {

	@Autowired
	private UsersService usersService; // 账户信息Service
	@Autowired
	private UsersConfigService usersConfigService;
	@Autowired
	private UsersRebateConfigService usersRebateConfigService;
	@Autowired
	private CallbackRedirectTableService callbackRedirectTableService;

	// 账户配置主页
	@RequestMapping("/allocations_index")
	public ModelAndView index(HttpSession session) {
		Object obj_id = session.getAttribute("adminUserId"); // 登录的用户ID
		if (obj_id == null) {
			return new ModelAndView("jsp/loginCheck"); // 未登录
		}
		CallbackRedirectTable callbackRedirectTable=callbackRedirectTableService.selectByUserId(obj_id.toString());
		Map<String,Object> map= Maps.newHashMap();
		map.put("users",usersService.selectByPrimaryKey((String) obj_id));
		if (callbackRedirectTable!=null && callbackRedirectTable.getRedirectUrl()!=null){
			map.put("callbackurl",callbackRedirectTable.getRedirectUrl());
		}

		return new ModelAndView("jsp/allocations_index", map);
	}

	// 账户其他配置主页
	@RequestMapping("/other_allocations_index")
	public ModelAndView otherIndex(HttpSession session) {
		Object obj_id = session.getAttribute("adminUserId"); // 登录的用户ID
		if (obj_id == null) {
			return new ModelAndView("jsp/loginCheck"); // 未登录
		}
		return new ModelAndView("jsp/other_allocations_index", "users", usersRebateConfigService.selectByParentId((String) obj_id));
	}

	// 账户其他配置主页
	@RequestMapping("/wx_allocations_index")
	public ModelAndView wxIndex(HttpSession session) {
		Object obj_id = session.getAttribute("adminUserId"); // 登录的用户ID
		if (obj_id == null) {
			return new ModelAndView("jsp/loginCheck"); // 未登录
		}
		return new ModelAndView("jsp/wx_allocations_index", "users", usersConfigService.selectByParentId((String) obj_id));
	}

	// 账户其他配置主页
	@RequestMapping("/member_allocations_index")
	public ModelAndView memberIndex(HttpSession session) {
		Object obj_id = session.getAttribute("adminUserId"); // 登录的用户ID
		if (obj_id == null) {
			return new ModelAndView("jsp/loginCheck"); // 未登录
		}
		return new ModelAndView("jsp/member_allocations_index", "users", usersConfigService.selectByParentId((String) obj_id));
	}
}
